/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  XESConvertor.java                                      
 *  File Contents Outline :  XES转换
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package cn.edu.thu.log.xes;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.regex.Pattern;

import org.deckfour.xes.classification.XEventAttributeClassifier;
import org.deckfour.xes.extension.XExtension;
import org.deckfour.xes.extension.XExtensionManager;
import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.factory.XFactory;
import org.deckfour.xes.factory.XFactoryRegistry;
import org.deckfour.xes.info.XLogInfo;
import org.deckfour.xes.info.XLogInfoFactory;
import org.deckfour.xes.model.XAttribute;
import org.deckfour.xes.model.XAttributeMap;
import org.deckfour.xes.model.XEvent;
import org.deckfour.xes.model.XLog;
import org.deckfour.xes.model.XTrace;
import org.deckfour.xes.model.impl.XAttributeLiteralImpl;
import org.deckfour.xes.out.XesXmlSerializer;

import cn.edu.thu.log.clean.NoiseIdentify1;
import cn.edu.thu.log.filter.logfilter.LogFilter;
import cn.edu.thu.log.read.LogBuffer;
import cn.edu.thu.log.read.LogConfig;
import cn.edu.thu.log.read.LogFilesReader;
import cn.edu.thu.log.util.Format;

import cn.edu.thu.log.util.PanGuConstants;
import cn.edu.thu.log.util.Timer;
import cn.edu.thu.log.web.service.LogCleanConfigReadService;
import cn.edu.thu.log.web.service.WebConfigReadService;
import cn.edu.thu.log.web.service.impl.LogCleanConfigReadServiceImpl;
//import globalparameter.TempFilePosition;
import cn.edu.thu.log.web.service.PropertiesReaderServices;
import cn.edu.thu.log.web.service.impl.PropertiesReaderServicesImpl;
import java.io.*;
import java.util.*;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import storage.dbhelper.LogBodyHelper;
import storage.dbhelper.LogHeadHelper;
import storage.dbhelper.XESHelper;
import storage.dbobject.DbLogBody;
import storage.dbobject.DbLogHead;
import storage.dbobject.DbXES;


public class XESConvertor {
//activePGIDList

    String classify;
    //  List<String> activeList;
    //  int fitEvent = 0;
    int clock = 0;
    final String BRANCH = "-bn";
    int numOfEvent = 0;
    int oldNumOfEvent = 0;
    private int totalEvent = 0;
    int XESBranch = 0;
    String currentTimeString;
    public static XFactory factory;
    XLog logReplace;
    WebConfigReadService xesConfig;
    String filePath;
    String timestampTag;
    String resultFilePath;
    XLog log;
    /**
     * map of latest trace from each caseID
     */
    private Hashtable<String, XTrace> caseTraceMap;
    private Hashtable<String, Integer> caseBranchMap;
    // from logContent
    ArrayList<String> cateList;
    LogConfig logConfig;
    XEventAttributeClassifier classifier;
    XExtensionManager extensionManager;
    // for logBuffer clean and noise detect
    LogBuffer testLogBuffer = new LogBuffer();
    //log format 
    String logHeadTokenizer;
    String logBodyTokenizer;
    String logHeadBodyTokenizer;
    //caseIDTagList
    ArrayList<String> caseIDTagList;
    //LogHeadTag
    ArrayList<String> logHeadTagList;
    //AvtivityList       
    ArrayList<String> activityTagList;
    ArrayList<String> activityAbbreList;
    ArrayList<String> activityLocList;
    Hashtable<String, String> activityNameLocMap;
    //AttributeList       
    ArrayList<String> attributeTagList;
    ArrayList<String> attributeAbbreList;
    ArrayList<String> attributeLocList;
    //   ArrayList<String> attributeLocList;
    Hashtable<String, String> tagAbbreLocMap;
    String classifyTags;
    // setupTimeStamp
    String timeStampIndentifier;//dm
    int timeStampLoc = 0;
    //caseIDLocation
    ArrayList<Integer> caseIDLocList;
    // time
    long time1_3_ReadFile = 0;
    long time4_WriteXES = 0;
    private long timeTotal = 0;
    long time_setLogBuffer = 0;
    long time_splitLog = 0;
    long time_WriteToEvent = 0;
    long time_WriteEventToLog = 0;
    long timeDetail_initialize = 0;
    long timeDetail_clean = 0;
    long time_noise = 0;
    long time_classify = 0;
    /**
     * noise Identifier
     */
    NoiseIdentify1 noiseidentify1;
    LogCleanConfigReadService readLogCleanConfigService;

    /**
     * Constructor
     *
     * @param xesConfig Reader to read configFile
     * @param filePath the file to save the result log
     */
    public XESConvertor(WebConfigReadService xesConfig, String filePath) {
        factory = XFactoryRegistry.instance().currentDefault();
        // XFactoryRegistry.instance().setSizeOfShadowMap(10);
        this.xesConfig = xesConfig;
        this.filePath = filePath;
        logConfig = new LogConfig();

        noiseidentify1 = new NoiseIdentify1();
        readLogCleanConfigService = LogCleanConfigReadServiceImpl.instance();

    }

    public XESConvertor(WebConfigReadService xesConfig, String filePath, String classify) {
        factory = XFactoryRegistry.instance().currentDefault();
        // XFactoryRegistry.instance().setSizeOfShadowMap(10);
        this.xesConfig = xesConfig;
        this.filePath = filePath;
        logConfig = new LogConfig();

        noiseidentify1 = new NoiseIdentify1();
        readLogCleanConfigService = LogCleanConfigReadServiceImpl.instance();
        this.classify = classify;
    }

    /**
     * entry function for write
     *
     * @param readfile file need to be read
     * @param logUI GUI for test/ it is not used here
     * @return
     */
    public void write(String resultfilePath) throws Exception {
        System.out.println("start write");
        Timer timerTotal = new Timer();
        timerTotal.start();
        // initialize
        this.resultFilePath = resultfilePath;
        LogFilesReader logfilesReader = new LogFilesReader();
        cateList = new ArrayList<String>();
        cateList = logfilesReader.getCateList(filePath);
        File readfile = new File(filePath);
        log = factory.createLog();
        logReplace = factory.createLog();
        XESConvertorMonitor.instance().numOfEvent = 0;

        System.out.print("\nset up log\n");
        caseTraceMap = new Hashtable<String, XTrace>();
        caseBranchMap = new Hashtable<String, Integer>();

        // setup avtivityClassifier
        setupClassifier();
        // setup extensions
        setupExtensions();
        // setup global attributes
        setupGlobalAttributes();
        //initialize the config and logHead format
        initConfig();

        // read File or Directory
        Timer timer = new Timer();
        timer.start();
        readFile(readfile);
        System.out.print("\nfinish ReadFile\n");

        //split the remaining log
        splitFinalLog();
        System.out.print("\nTotal num of events: " + getTotalEvent());
        timer.stop();
        time1_3_ReadFile += timer.getDuration();
        timer.start();

        // write remaining log and logReplace
        System.out.print("\nsize of log before write to XES:" + numOfEvent);
        System.out.print("\nsize of logReplace before write to XES:"
                + XESConvertorMonitor.instance().numOfEvent);
        //   XESConvertorMonitor.instance().deleteNotFit(log);
        //    XESConvertorMonitor.instance().deleteNotFit(logReplace);
        writeToXES(log);
        writeToXES(logReplace);
        timer.stop();
        time4_WriteXES += timer.getDuration();
        timerTotal.stop();
        setTimeTotal(getTimeTotal() + timerTotal.getDuration());
        // display the timer
        System.out.print("\n---time symmary-----");
        System.out.print("\ntime1_3_ReadFile:"
                + Timer.formatDuration(time1_3_ReadFile));
        System.out.print("\ntime4_WriteXES:"
                + Timer.formatDuration(time4_WriteXES));
        System.out.print("\ntimeDetail_initializet:"
                + Timer.formatDuration(timeDetail_initialize));
        System.out.print("\ntimeDetail_clean:"
                + Timer.formatDuration(timeDetail_clean));
        System.out.print("\ntime_setLogBuffer:"
                + Timer.formatDuration(time_setLogBuffer));
        System.out.print("\ntime_WriteToEvent:"
                + Timer.formatDuration(time_WriteToEvent));
        System.out.print("\ntime_WriteEventToLog:"
                + Timer.formatDuration(time_WriteEventToLog));
        System.out.print("\ntime_splitLog:"
                + Timer.formatDuration(time_splitLog));
        System.out.print("\ntotalTime:"
                + Timer.formatDuration(getTimeTotal()));
        return;
    }

    /**
     * set up classifier for log
     */
    private void setupClassifier() {
        String[] keys = {XConceptExtension.KEY_NAME};
        classifier = new XEventAttributeClassifier("activity classifier", keys);
        log.getClassifiers().add(classifier);

    }

    // set up extensions for log
    private void setupExtensions() {
        XExtension timeExtension = XTimeExtension.instance();
        XExtension conceptExtension = XConceptExtension.instance();
        log.getExtensions().add(timeExtension);
        log.getExtensions().add(conceptExtension);

    }

    // set up global attributes
    private void setupGlobalAttributes() {


        XAttribute attributeConcept = factory.createAttributeLiteral(
                XConceptExtension.KEY_NAME, "name", null);
        log.getGlobalEventAttributes().add(attributeConcept);
        XAttribute attributeTime = factory.createAttributeLiteral(
                XTimeExtension.KEY_TIMESTAMP, "time", null);
        log.getGlobalEventAttributes().add(attributeTime);

        log.getGlobalTraceAttributes().add(attributeConcept);
    }

    //initialize the config and logHead format
    private void initConfig() throws Exception {
        //   activeList = Temp.getActivePGID();
        //logConfig.config(PanGuConstants.LOGREAD_CONFIGFILE);
        logConfig.config();
        logHeadTokenizer = logConfig.getLogHeadTokenizer();
        logBodyTokenizer = logConfig.getLogBodyTokenizer();
        logHeadBodyTokenizer = logConfig.getLogHeadBodyTokenizer();
//        System.out.println(logHeadTokenizer + logBodyTokenizer + logHeadBodyTokenizer);

        // setUpcaseIDList
        caseIDTagList = xesConfig.getPattern().getCaseIDList();//dm
        System.out.println("caseIDTagList here:" + caseIDTagList);
        // mainCase
        String mainCase = xesConfig.getPattern().getMainCaseID();//dm
        if (caseIDTagList.isEmpty()) {
            caseIDTagList.add(mainCase);
        }
       System.out.println("caseIDTagList:" + caseIDTagList);
        tagAbbreLocMap = new Hashtable<String, String>();
        //setLogHeadTag
        logHeadTagList = xesConfig.getVersion().getLogHeadList();//dm
        // System.out.println();
        System.out.println("logHeadTagList:" + logHeadTagList);
        //setAvtivityList       
        activityTagList = xesConfig.getPattern().getActivityList();//dm
        activityAbbreList = new ArrayList<String>();
        activityLocList = new ArrayList<String>();
        activityNameLocMap = new Hashtable<String, String>();
        setActivityAbbre(activityTagList, activityAbbreList, activityLocList);
        //     System.out.println("setActivityAbbre:"+activityTagList);

        classifyTags = xesConfig.getPattern().getClassifytag();
        readLogCleanConfigService.setClassifyTags(classifyTags);
         System.out.println("classifyTags:" + classifyTags);

        //setAttributeList
        attributeTagList = xesConfig.getPattern().getAttributeList();//dm
        // System.out.println("attributeTagList:"+attributeTagList);
        attributeAbbreList = new ArrayList<String>();
        attributeLocList = new ArrayList<String>();
        setActivityAbbre(attributeTagList, attributeAbbreList, attributeLocList);
        System.out.println("attributeTagList:" + attributeTagList);
        System.out.println("attributeAbbreList:" + attributeAbbreList);
        System.out.println("attributeLocList:" + attributeLocList);

        // setupTimeStamp and timeStamp location
        timeStampIndentifier = xesConfig.getPattern().getTimeStamp();//dm
        for (int j = 0; j < logHeadTagList.size(); j++) {
            if (timeStampIndentifier.equalsIgnoreCase(logHeadTagList.get(j))) {
                timeStampLoc = getLogHeadLoc(j);
            }
        }

        //setup caseID and caseID location
        caseIDLocList = new ArrayList<Integer>();


        for (int i = 0; i < caseIDTagList.size(); i++) {
            String caseID = caseIDTagList.get(i);
            System.out.println("caseID:" + caseID);
            for (int j = 0; j < logHeadTagList.size(); j++) {
                if (caseID.equalsIgnoreCase(logHeadTagList.get(j))) {
                    int loc = getLogHeadLoc(j);
                    // System.out.println("getLogHeadLoc返回值："+loc);
                    caseIDLocList.add(loc);

                }
            }
        }
//        System.out.println("caseIDLocList:" + caseIDLocList);
    }

    /**
     * reader for file/Directory
     *
     * @param readfile log file
     * @param logUI GUI for test
     */
    private void readFile(File readfile) {
        if (!readfile.isDirectory()) {
            //如果选择了日志清洗规则，则读取规则生成tree
            if (readLogCleanConfigService.getNoiseflag() == 1) {
                noiseidentify1.readNoiseIdetifyConfigFile(readLogCleanConfigService);
            }
            readFileContent(readfile);
        } else if (readfile.isDirectory()) {
            File[] fileList = readfile.listFiles();
            for (int i = 0; i < fileList.length; i++) {
                File editfile = fileList[i];
                if (!editfile.isDirectory()) {
                    readFileContent(editfile);

                } else if (editfile.isDirectory()) {
                    readFile(editfile);
                }
            }
        }
    }

    /**
     * read content of one file
     *
     * @param file log file
     * @param logUI GUI for test
     */
    private void readFileContent(File file) {
        // System.out.println("读取下一个file");
        Timer timer = new Timer();

        String logHeadContent = "";
        String logBodyContent = "";
        LogBuffer logBuffer;
        // XES event
        XEvent event;
        // read each log Record
        BufferedReader reader;
        //   String recordTemp;
        String record;
        try {
            System.out.println("file:"+file);
            FileInputStream fr = new FileInputStream(file);
            InputStreamReader is = new InputStreamReader(fr, "UTF-8");
            reader = new BufferedReader(is);
            //  reader = new BufferedReader(new FileReader(file));

            // deal file by line
            while ((record = reader.readLine()) != null) {

                // record=URLEncoder.encode(recordTemp, "UTF-8");
                //    System.out.println("recordTemp:"+recordTemp);
                //   System.out.println("record:" + record);
                timer.start();
                Timer timerDetail = new Timer();

                // initialize
                event = factory.createEvent();
                logBuffer = new LogBuffer();
                String temprecord = record;
                ArrayList<Object> params = new ArrayList<Object>();
                ArrayList<Object> headparams = new ArrayList<Object>();
                ArrayList<Object> bodyparams = new ArrayList<Object>();
                Hashtable<String, String> bodyMap;
                // split log head and log body
                String patternString = "[^\\\\]";
                patternString = patternString.concat(logHeadBodyTokenizer);
                Pattern pattern = Pattern.compile(patternString);
                String[] strs = pattern.split(temprecord);
                if (strs[0].length() == temprecord.length()) {//only loghead
                    continue;
                }
                if (strs.length <= 1) {//only loghead or logbody
//                System.out.println("temprecord:"+temprecord);
                    continue;
                }
                logHeadContent = strs[0].concat(String.valueOf(temprecord.charAt(strs[0].length())));

                logBodyContent = strs[1];
                // set up log Head params
//                ArrayList<String> temp = Format.splitContentToList(logHeadTokenizer,
//                        logHeadContent);
//                headparams.addAll(temp);
//                if (temp.toString().contains(", , , , , , ,")) {
//                    System.out.println("temp:" + temp);
//                }
                headparams.addAll(Format.splitContentToList(logHeadTokenizer,
                        logHeadContent));
                // set up logBody params
                bodyparams.addAll(Format.splitContentToList(logBodyTokenizer,
                        logBodyContent));
                bodyMap = Format.splitContentToMap(logBodyTokenizer, logBodyContent);
                //   Enumeration enu = bodyMap.keys();
//                while(enu.hasMoreElements()){
//                    String key=(String) enu.nextElement();
//                    System.out.println("key:"+key);
//                     System.out.print("\tvalue:"+bodyMap.get(key));
//                }
                // set up log Content
                params.addAll(headparams);
                params.addAll(bodyparams);


                /*
                 * ---set up logBuffer and put it into event-------
                 */
                logBuffer.setLogBodyMap(bodyMap);
                logBuffer.setLogPath(file.getAbsolutePath());
                logBuffer.setLogHeadContent(headparams);
                logBuffer.setLogBodyContent(bodyparams);
                logBuffer.setLogBody(logBodyContent);
                logBuffer.setLogContent(params);

                logBuffer.setLogHeadTagList(logHeadTagList);//dm


                /**
                 * noise test and clean test for logBuffer
                 */
                timerDetail.start();
                setTestLogBuffer(logBuffer);

                /**
                 * 首先扫描判断记录的日志头是否与要求的一致
                 */
                if (logBuffer.getLogHeadTagList().size() != logBuffer.getLogHeadContent().size()) {
//			System.out.print("\nfound dirty log record, record discarded");
                    //     System.out.print("\tloghead tag size:" + logBuffer.getLogHeadTagList().size());
                    //    System.out.print(" != log content size: "
                    //      + logBuffer.getLogHeadContent().size());
                    continue;
                }
//                //temp for PGID +Referer
//
//                if (!activeList.contains(headparams.get(13))) {//PGID
//                    continue;
//                } else {
//                 //   System.out.println("contasin");
//                }
//                String Referer=headparams.get(11).toString();
//                 //  System.out.println("before:"+Referer);
//                if (Referer.length()!=0) {//Referer
//                 headparams.set(11, Temp.cutURL(Referer)) ;
//               //  System.out.println("afer:"+headparams.get(11));
//                } 
////temp end

                //temp for otherclick 

//                 if (!headparams.get(8).toString().equals("image")){//contetnType
//                     continue;
//                 }
//                 else{
//                //  System.out.print("match news");
//                 }
//                 if (!bodyMap.get("pt").equals("435")){//contetnType
//                       //  System.out.print("not match pt 330:"+bodyMap.get("pt"));
//                     continue;
//                 }
//                 else{
//                     System.out.print("match pt 435:"+bodyMap.get("pt"));
//                 }  
                //end temp for otherclick 


                //temp for vastr

//                if (!activeList.contains(headparams.get(13))) {//PGID
//                    continue;
//                } else {
//                 //   System.out.println("contasin");
//                }
//                String Referer=headparams.get(11).toString();
//                // System.out.println("before:"+Referer);
//                if(!Referer.contains("pangu"))
//                {
//                    continue;
//                }
//                if (Referer.length()!=0) {//Referer
//                 headparams.set(11, Temp.cutURL(Referer)) ;
//               //  System.out.println("afer:"+headparams.get(11));
//                } 
//temp end
                //活动抽象,如果活动列表中包括这个字段，则转换为xes时，修改logbuffer，否则不修改
                //由于是单个字段修改，而不是组合字段，则直接在日志清洗的时候进行

                //日志清洗、噪声识别,在清洗中实现分段规则
                //  System.out.println(" before logBuffer.getLogHeadContent():"+ logBuffer.getLogHeadContent());
                Timer noiseTimer = new Timer();
                if (readLogCleanConfigService.getNoiseflag() == 1) {
                    //  System.out.println("start clean");
                    noiseTimer.start();
//                    noiseidentify1.readNoiseIdetifyConfigFile(readLogCleanConfigService);
                    if (noiseidentify1.logNoise(logBuffer)) {

                        continue;
                    } else {
                        //  System.out.println("no noise. after logBuffer.getLogHeadContent():"+ logBuffer.getLogHeadContent());
                    }
                    noiseTimer.stop();
                    time_noise += time_noise += timer.getDuration();
                    //   System.out.println("\ntime_noise:"+Timer.formatDuration(time_noise));
                } //如果没有设置清洗规则，但是设定了分段
                else if (!readLogCleanConfigService.getClassifyTags().equals("")) {
                    noiseTimer.start();

                    LogFilter logfilter = new LogFilter();
                    logfilter.setClassifyTags(classifyTags);

                    logfilter.filter(logBuffer);


                    noiseTimer.stop();
                    time_classify += noiseTimer.getDuration();

                }

                timerDetail.stop();
                timeDetail_clean = timeDetail_clean + timerDetail.getDuration();
                timerDetail.start();


                // set timeStamp(content) to logBuffer
                String timeStampContent = logBuffer.getLogHeadContent().get(timeStampLoc).toString();
                logBuffer.setTimeStamp(timeStampContent);

                // set caseID tag and content to LogBuffer
                ArrayList<String> caseIDContentList = new ArrayList<String>();
                String logCaseIDString = new String("");
                for (int i = 0; i < caseIDLocList.size(); i++) {
                    int caseIDLoc = caseIDLocList.get(i);
                    if (caseIDLoc <= logBuffer.getLogHeadContent().size()) {

                        String caseIDContent = logBuffer.getLogHeadContent().get(caseIDLoc).toString();
//                              System.out.println(" logBuffer.getLogHeadContent():"+ logBuffer.getLogHeadContent());
//                                      System.out.println("caseIDLoc"+ caseIDLoc);
//                          System.out.println("caseIDContent:"+caseIDContent);

                        caseIDContentList.add(caseIDContent);
                        logCaseIDString += caseIDContent + ",";
                    } else {
                        caseIDContentList.add("NA");
                        logCaseIDString += "NA" + ",";
                        // System.out.println("activity not in logHead");
                    }

                }
                logBuffer.setCaseIDList(caseIDContentList);
//                System.out.println("caseIDContentList");
                logBuffer.setCaseIDString(logCaseIDString);

                //set activityContent to LogBuffer
                ArrayList<Object> activityIDContentList = new ArrayList<Object>();
                for (int l = 0; l < activityAbbreList.size(); l++) {
                    String activityAbbre = activityAbbreList.get(l);
                    activityIDContentList.add(activityAbbre + ":" + bodyMap.get(activityAbbre));
//                    int startIndex = logBuffer.getLogBody().indexOf(activityAbbre + ":");
//                    if (startIndex >= 0) {
//                        String subString = logBuffer.getLogBody().substring(startIndex);
//                        int endIndex = subString.indexOf(logBodyTokenizer);
//                        String activityContent = subString.substring(0, endIndex);
//                        
//                    }
                }

                for (int l = 0; l < activityLocList.size(); l++) {
                    String activityLoc = activityLocList.get(l);
                    int loc = Integer.parseInt(activityLoc) - 1;
                    if (loc <= logBuffer.getLogHeadContent().size()) {
                        Object activityL = logBuffer.getLogHeadContent().get(loc);
                        if (activityL != null) {
                            if (activityL.toString().length() > 0) {
                                activityIDContentList.add(activityNameLocMap.get(activityLoc) + ":" + activityL);
                            } else {
                                activityIDContentList.add("NA");
                            }
                        }
                    } else {
                        activityIDContentList.add("NA");
                        // System.out.println("activity not in logHead");
                    }
                }
                //have not found match avtivity
                if (activityIDContentList.size() == 0) {

                    continue;//dm
                }
                //  System.out.println("activityIDContentList:" + activityIDContentList);
                logBuffer.setActivityIDContentList(activityIDContentList);



                //set attributeLiat to LogBuffer
                Hashtable<String, String> attributeIDContenMap = new Hashtable<String, String>();//<TagName,TagContent>
                for (int l = 0; l < attributeAbbreList.size(); l++) {
                    String attributeAbbre = attributeAbbreList.get(l);

//                    if (!tagAbbreLocMap.containsKey(attributeAbbre)) {
//                        System.out.println("!tagAbbreLocMap.containsKey(attributeAbbre):" + attributeAbbre);
//                    }
//                    if (!bodyMap.containsKey(attributeAbbre)) {
//                        System.out.println("!bodyMap.contains(attributeAbbre):" + attributeAbbre);
//                    }
//              else {
//                        System.out.println("bodyMap.contains(attributeAbbre):" + attributeAbbre);
//                    }
                    String tagName = tagAbbreLocMap.get(attributeAbbre);
                    String bodyContent = bodyMap.get(attributeAbbre);
                    if (bodyContent != null) {
                        if (bodyContent.toString().length() > 0) {
                            attributeIDContenMap.put(tagName, bodyContent);
                        } else {
                            attributeIDContenMap.put(tagName, "NA");
                        }
                        //attributeIDContenMap.put(tagName, bodyContent);
                    } else {
                        attributeIDContenMap.put(tagName, "NA");
                    }
                }
                for (int l = 0; l < attributeLocList.size(); l++) {
                    String attributeLoc = attributeLocList.get(l);
                    int loc = Integer.parseInt(attributeLoc);
                    if (loc < logBuffer.getLogHeadContent().size()) {
                        String tagName = tagAbbreLocMap.get(String.valueOf(loc));
                        Object headContent = logBuffer.getLogHeadContent().get(loc - 1);
                        //   Object attributeL = logBuffer.getLogHeadContent().get(loc);
                        if (headContent != null) {
                            if (tagName == null) {
                                //   System.out.println("(tagName==null:loc:" + loc);
                            }
                            if (headContent.toString().length() > 0) {
                                attributeIDContenMap.put(tagName, headContent.toString());
                            } else {
                                attributeIDContenMap.put(tagName, "NA");
                            }
                            // attributeIDContenMap.put(tagName, headContent.toString());
                        } else {
                            attributeIDContenMap.put(tagName, "NA");
                        }
                    }
                }
//                //have not found match attribute
//                if (attributeIDContentList.size() == 0) {
//
//                    continue;//dm
//                }

                logBuffer.setAttributeIDContentMap(attributeIDContenMap);
                timerDetail.stop();
                timeDetail_initialize = timeDetail_initialize + timerDetail.getDuration();

                timer.stop();
                time_setLogBuffer = time_setLogBuffer + timer.getDuration();

                // set logBuffer to event
                timer.start();
                writeEvent(event, logBuffer);
                timer.stop();
                time_WriteToEvent = time_WriteToEvent + timer.getDuration();
                /*
                 * ---put event to trace,trace to log-------
                 */
                timer.start();
                putEventToLog(logBuffer, event);
                timer.stop();
                time_WriteEventToLog = time_WriteEventToLog + timer.getDuration();
            }
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * get teh location of content in logHead
     *
     * @param tagLocation the location of the tag in tagList
     * @return the location of content in contentList in logHead
     */
    private int getLogHeadLoc(int tagLocation) {
        LogHeadHelper logHeadH = new LogHeadHelper();
        List<DbLogHead> logHeadTags = logHeadH.getLogHeads(DbLogHead.cl_name, logHeadTagList.get(tagLocation));
        DbLogHead logHeadTag = logHeadTags.get(0);
        String locString = logHeadTag.getLocation();

        int loc = Integer.parseInt(locString) - 1;
        return loc;
    }

    /**
     * set up the activity tag in each logBuffer
     *
     * @param activityIDTagList the activities' tags eat up by user
     * @param logTagList the tag list read from config reader
     * @return the list of location of activityTag in whole tagList
     */
    private void setActivityAbbre(
            ArrayList<String> actvityList, ArrayList<String> activityAbbreList, ArrayList<String> activityLocList) {

        LogBodyHelper logBodyH = new LogBodyHelper();
        LogHeadHelper logHeadH = new LogHeadHelper();
        //  System.out.println("important:actvityList size:" + actvityList.size() + "\n" + actvityList);
        for (int i = 0; i < actvityList.size(); i++) {
            String activityName = actvityList.get(i);
            //System.out.println("important:activityName:" + activityName);
            List<DbLogBody> logBodys = logBodyH.getLogBodys(DbLogBody.cl_name, activityName);

            if (logBodys.size() != 0) {//avtivity belong to logBody
                DbLogBody logBody = logBodys.get(0);
                String abbre = logBody.getAbbreviation();
                activityAbbreList.add(abbre);
                if (!tagAbbreLocMap.contains(abbre)) {
                    tagAbbreLocMap.put(abbre, activityName);
                    // System.out.println("tagAbbreLocMap.put abbre:" + abbre+" activityName:"+activityName);
                }

            } else {//avtivity belong to logHead
                List<DbLogHead> logHeads = logHeadH.getLogHeads(DbLogHead.cl_name, activityName);
                if (logHeads.size() != 0) {
                    DbLogHead logHead = logHeads.get(0);
                    String location = logHead.getLocation();

                    activityLocList.add(location);
                    if (!tagAbbreLocMap.contains(location)) {
                        tagAbbreLocMap.put(location, activityName);
                        if (!activityNameLocMap.containsKey(location)) {
                            activityNameLocMap.put(location, activityName);
                        }
                        //   System.out.println("tagAbbreLocMap.put location:" + location+" activityName:"+activityName);
                    }

                }

            }

        }
        return;
    }

    /**
     * write activities,logPath,caseID to event
     *
     * @param event
     * @param logBuffer
     */
    private void writeEvent(XEvent event, LogBuffer logBuffer) {

        // get content of this event
        ArrayList<Object> logActivityContents = logBuffer.getActivityIDContentList();
        // create a event
        XAttributeMap attributeMap = factory.createAttributeMap();

        // put the log tags as attributes to attributeMap
        String activityVal = "";
        for (int i = 0; i < logActivityContents.size(); i++) {
            if (logActivityContents.get(i) != null) {
                String logActivityL = logActivityContents.get(i).toString();//ww
//                fitEvent = XESConvertorMonitor.instance().ifFit(logActivityL);//ww
//                if (fitEvent == 1) {
//                    logActivityL = XESConvertorMonitor.instance().trimAvtivity(logActivityL);
//                }
                if (i == 0) {
                    activityVal = logActivityL;
                } else {
                    activityVal = activityVal + "," + logActivityL;
                }
                //  System.out.println("logActivityL:"+logActivityL);


            }
        }
        //  System.out.println("activityVal:"+activityVal);
        if (activityVal.length() > 0) {
            XAttribute attribute = factory.createAttributeLiteral(
                    XConceptExtension.KEY_NAME, activityVal, null);
            attributeMap.put(XConceptExtension.KEY_NAME, attribute);

        } else {
            XAttribute attribute = factory.createAttributeLiteral(
                    XConceptExtension.KEY_NAME, "NA", null);
            attributeMap.put(XConceptExtension.KEY_NAME, attribute);
        }

        // get attribute of this event
        Hashtable<String, String> logAttibuteContentMap = logBuffer.getAttributeIDContentMap();
        Enumeration keyEnumer = logAttibuteContentMap.keys();
        // put the log tags as attributes to attributeMap

        while (keyEnumer.hasMoreElements()) {
            String attributeTagName = keyEnumer.nextElement().toString();
            String attributeContent = logAttibuteContentMap.get(attributeTagName);
            if (attributeContent != null && attributeContent.length() > 0) {
                XAttribute attribute = factory.createAttributeLiteral(
                        attributeTagName, attributeContent, null);
                attributeMap.put(attributeTagName, attribute);
            } else {//content==null or content=""
                XAttribute attribute = factory.createAttributeLiteral(
                        attributeTagName, "NA", null);
                attributeMap.put(attributeTagName, attribute);
            }

        }

        //add logPath attribute to map
        XAttribute attributePath = factory.createAttributeLiteral(PanGuConstants.LOGPATH_ATTRIBUTE,
                logBuffer.getLogPath(), null);
        attributeMap.put(attributePath.getKey(), attributePath);
        // add timestamp attribute to map
        String timeString = logBuffer.getTimeStamp();
        Date timeStamp = Format.StringToTimeStamp(timeString);
        XAttribute attributeTime = factory.createAttributeTimestamp(
                XTimeExtension.KEY_TIMESTAMP, timeStamp, null);
        attributeMap.put(attributeTime.getKey(), attributeTime);
        currentTimeString = timeString;
        // set event's AttributesMap
        event.setAttributes(attributeMap);
    }

    /**
     * put event into log
     *
     * @param logBuffer the logBuufer that contains the informatino of event
     * @param event the event
     * @param logCaseIDString the caseID of logBuffer
     */
    private void putEventToLog(LogBuffer logBuffer, XEvent event) {

        // get caseID for this logBuffer
        String logCaseIDString = logBuffer.getCaseIDString();
        // if map already contains this event's caseID
        if (caseBranchMap.containsKey(logCaseIDString)) {
            int latsetBranchNum = caseBranchMap.get(logCaseIDString);

            // time out, build a new trace with new branch

            if (!caseTraceMap.containsKey(logCaseIDString))// timeout
            {
                String newCaseID = logCaseIDString + BRANCH
                        + (latsetBranchNum + 1);
                XTrace traceNew = factory.createTrace();
                // add branch to case map
                caseBranchMap.put(logCaseIDString, latsetBranchNum + 1);
                caseTraceMap.put(logCaseIDString, traceNew);
                XAttributeMap traceAttributeMapNew = factory.createAttributeMap();
                XAttribute traceAttributeID = factory.createAttributeLiteral(
                        XConceptExtension.KEY_NAME, newCaseID, null);
                traceAttributeMapNew.put(traceAttributeID.getKey(),
                        traceAttributeID);
                traceNew.setAttributes(traceAttributeMapNew);
                traceNew.add(event);
                log.add(traceNew);//2

                XESConvertorMonitor.instance().updateLastestArrivalMap(
                        traceNew, logBuffer.getTimeStamp());
//                XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 0);//ww
//                if (fitEvent == 1) {//fit//ww
//                    XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 1);//ww
//                }//ww

            } else //event in caseTraceMap
            {

//                if (!log.contains(lastTrace)) {
//                    System.out.print("\nlog does not contains this trace");
//                }
                XTrace lastTrace = caseTraceMap.get(logCaseIDString);
                boolean ifTimeOut = XESConvertorMonitor.instance().ifTimeOut(
                        logBuffer, lastTrace);
                if (ifTimeOut) {
                    String newCaseID = logCaseIDString + BRANCH
                            + (latsetBranchNum + 1);
                    XTrace traceNew = factory.createTrace();
                    // add branch to case map
                    caseBranchMap.put(logCaseIDString, latsetBranchNum + 1);
                    //     System.out.println("logCaseIDString:"+logCaseIDString);
                    caseTraceMap.put(logCaseIDString, traceNew);
//                getCaseBranchMap().put(logCaseIDString, traceNew);
                    XAttributeMap traceAttributeMapNew = factory.createAttributeMap();
                    XAttribute traceAttributeID = factory.createAttributeLiteral(
                            XConceptExtension.KEY_NAME, newCaseID, null);
                    traceAttributeMapNew.put(traceAttributeID.getKey(),
                            traceAttributeID);
                    traceNew.setAttributes(traceAttributeMapNew);
                    traceNew.add(event);
                    log.add(traceNew);//1
                    XESConvertorMonitor.instance().updateLastestArrivalMap(
                            traceNew, logBuffer.getTimeStamp());
//                    XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 0);//ww
//                    if (fitEvent == 1) {//fit//ww
//                        XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 1);//ww
//                    }//ww

                } else {//not timeout
                    lastTrace.add(event);
                    XESConvertorMonitor.instance().updateLastestArrivalMap(
                            lastTrace, logBuffer.getTimeStamp());
//                    if (fitEvent == 1) {//fit//ww
//                        XESConvertorMonitor.instance().getFitTraceMap().put(lastTrace, 1);//ww
//                    }//ww

                }
            }

        } else {// do not has CaseID,then build a new trace
            XTrace traceNew = factory.createTrace();
            XAttributeMap traceAttributeMapNew = factory.createAttributeMap();

            String caseIDString = logBuffer.getCaseIDString();
            // add branch to case map
            caseBranchMap.put(caseIDString, 1);
            caseTraceMap.put(caseIDString, traceNew);
            //   System.out.println("new caseIDString"+caseIDString);
            //  getCaseBranchMap().put(caseIDString, traceNew);
            caseIDString = caseIDString.concat(BRANCH + 1);

            XAttribute traceAttributeNew = factory.createAttributeLiteral(
                    XConceptExtension.KEY_NAME, caseIDString, null);
            traceAttributeMapNew.put(traceAttributeNew.getKey(),
                    traceAttributeNew);
            traceNew.setAttributes(traceAttributeMapNew);

            traceNew.add(event);

//            XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 0);//ww
//            if (fitEvent == 1) {//fit//ww
//                XESConvertorMonitor.instance().getFitTraceMap().put(traceNew, 1);//ww
//                // System.out.println("event fit:");
//            }//ww

            // add new trace to log
            log.add(traceNew);//3
            XESConvertorMonitor.instance().updateLastestArrivalMap(traceNew,
                    logBuffer.getTimeStamp());
        }

        numOfEvent++;
        setTotalEvent(getTotalEvent() + 1);
        Timer timerSplitLog = new Timer();
        timerSplitLog.start();
        clock++;
        if (clock >= PanGuConstants.MAX_EVENT_NUM) {
            clock = 0;
            splitXLog();
        }

        timerSplitLog.stop();
        time_splitLog = time_splitLog + timerSplitLog.getDuration();
    }

    private void splitXLog() {
        if (numOfEvent > PanGuConstants.MUTIPLE_MAX_EVENT_NUM * PanGuConstants.MAX_EVENT_NUM) {
            Date currentTime = Format.StringToTimeStamp(currentTimeString);// the

            Iterator<XTrace> iterator = log.iterator();
            List<XTrace> tempXTraceList = new ArrayList<XTrace>();
            while (iterator.hasNext()) {
                XTrace currentTrace = iterator.next();
                String latestTime = XESConvertorMonitor.instance().getLastestArrivalMap().get(currentTrace);
                Date lasterTime = Format.StringToTimeStamp(latestTime);
                // complete trace
                if (Math.abs(currentTime.getTime() - lasterTime.getTime()) > PanGuConstants.TIMEROUT) {
                    //if trace not fit //ww
//                    if (XESConvertorMonitor.instance().getFitList().size() != 0 && XESConvertorMonitor.instance().getFitTraceMap().get(currentTrace) == 0)//not fit
//                    {
//                        //System.out.println("trace not fit:");
//                        tempXTraceList.add(currentTrace);//will be delete from log
//                        XESConvertorMonitor.instance().getFitTraceMap().remove(currentTrace);//will be delete from log
//                        numOfEvent = numOfEvent - currentTrace.size();
//                        continue;
//                    }//ww

                    logReplace.add(currentTrace);
                    XESConvertorMonitor.instance().numOfEvent = XESConvertorMonitor.instance().numOfEvent
                            + currentTrace.size();
                    XESConvertorMonitor.instance().getLastestArrivalMap().remove(currentTrace);//dd

                    tempXTraceList.add(currentTrace);
                    XAttributeMap map = currentTrace.getAttributes();
                    XAttribute tempAttribute = map.get(XConceptExtension.KEY_NAME);
                    String caseIDValue = ((XAttributeLiteralImpl) tempAttribute).getValue();
                    int pos = caseIDValue.lastIndexOf(BRANCH);
                    String caseIDWithoutBranch = caseIDValue.substring(0, pos);
                    String branch = caseIDValue.substring(pos + BRANCH.length());
                    if (caseBranchMap.containsKey(caseIDWithoutBranch) && caseBranchMap.get(caseIDWithoutBranch).toString().equalsIgnoreCase(branch)) {
                        caseTraceMap.remove(caseIDWithoutBranch);//remove complete trace
                        //  System.out.println("caseTraceMap.remove:" + caseIDWithoutBranch+ " branch:"+branch);
                    } else {
                        // System.out.println("currentCASEIDString:" + caseIDValue+ " branch:"+branch+" caseBranchMap.get(caseIDWithoutBranch):"+caseBranchMap.get(caseIDWithoutBranch)+" caseTraceMap.isEmpty():"+caseTraceMap.isEmpty());
                    }

                    if (XESConvertorMonitor.instance().ifExceedMaxEventNum()) {//logReplace has enough traces ,so write logReplace to xes
                        if (XESConvertorMonitor.instance().numOfEvent
                                - currentTrace.size() != 0) {
                            logReplace.remove(currentTrace);// 1
                            XESConvertorMonitor.instance().numOfEvent = XESConvertorMonitor.instance().numOfEvent
                                    - currentTrace.size();// 1
                            XESConvertorMonitor.instance().getLastestArrivalMap().put(currentTrace, latestTime);
                            tempXTraceList.remove(currentTrace);
                            caseTraceMap.put(caseIDWithoutBranch, currentTrace);
                        } else {
                            numOfEvent = numOfEvent - currentTrace.size();
                        }
                        System.out.print("\nsize of events in logReplace before writeToXES: "
                                + +XESConvertorMonitor.instance().numOfEvent);
                        System.out.print("\nsize of events in log before logReplace writeToXES: "
                                + numOfEvent);
                        writeToXES(logReplace);
                        logReplace = factory.createLog();
                        XESConvertorMonitor.instance().numOfEvent = 0;
                        continue;
                    } else {
//                        log.remove(currentTrace);
//                        //  XESConvertorMonitor.instance().getLastestArrivalMap().remove(currentTrace);//remove the trace that already been writen
                        numOfEvent = numOfEvent - currentTrace.size();
                    }
                }
            }
            //    System.out.println("\nlog.removeAll(tempXTraceList):" + tempXTraceList.size());
            log.removeAll(tempXTraceList);
        }

        return;
    }

    public void splitFinalLog() {
//        System.out.print("\nsplit final log");
//         System.out.println("numOFEvent" + numOfEvent);
//        System.out.println("getLogSize(log)" + getLogSize(log));
        while (numOfEvent > PanGuConstants.MAX_EVENT_NUM) {
            //   System.out.println("numOfEvent:"+numOfEvent);
            Iterator<XTrace> iterator = log.iterator();
            List<XTrace> tempXTraceList = new ArrayList<XTrace>();
            if (iterator.hasNext()) {
            } else {
                System.out.println("numOFEvent" + numOfEvent);
                System.out.println("!iterator.hasNext() log size:");
                // System.out.println("getLogSize(log)" + getLogSize(log));
            }
            while (iterator.hasNext()) {
                XTrace currentTrace = iterator.next();
//                if (XESConvertorMonitor.instance().getFitList().size() != 0 && XESConvertorMonitor.instance().getFitTraceMap().get(currentTrace) == 0)//not fit
//                {
//                    if (XESConvertorMonitor.instance().getFitTraceMap().get(currentTrace) == 0)//not fit
//                    {
//                        //      System.out.println("trace not fit:");
//                        tempXTraceList.add(currentTrace);//will be delete from log
//                        XESConvertorMonitor.instance().getFitTraceMap().remove(currentTrace);//will be delete from log
//                        numOfEvent = numOfEvent - currentTrace.size();
//                        continue;
//                    }//ww
//                }
                logReplace.add(currentTrace);
                XESConvertorMonitor.instance().numOfEvent = XESConvertorMonitor.instance().numOfEvent
                        + currentTrace.size();
                tempXTraceList.add(currentTrace);

                if (XESConvertorMonitor.instance().numOfEvent > PanGuConstants.MAX_EVENT_NUM) {

                    //logReplace.remove(currentTrace);// 1
//                    XESConvertorMonitor.instance().numOfEvent = XESConvertorMonitor.instance().numOfEvent
//                            - currentTrace.size();
                    // tempXTraceList.remove(currentTrace);
                    numOfEvent = numOfEvent - currentTrace.size();
                    System.out.print("\nsplit final log:size in logReplace before writeToXES: "
                            + XESConvertorMonitor.instance().numOfEvent);
                    System.out.print("\nsplit final log:size in log before logReplace writeToXES: " + numOfEvent);

                    writeToXES(logReplace);
                    logReplace = factory.createLog();

                    XESConvertorMonitor.instance().numOfEvent = 0;
                    break;
                } else {
                    numOfEvent = numOfEvent - currentTrace.size();
                }
            }
            log.removeAll(tempXTraceList);
        }
    }

    /**
     * write log to xes file() function for test
     */
    private void writeToXESLocal(XLog writeLog) {
        // wirteLog is empty
        if (writeLog.size() == 0) {
            return;
        }
        // get the size of events in writeLog
        System.out.print("\nwrite to XES");
        try {
            String name = resultFilePath + "_" + XESBranch + ".xes";
            File sFile = new File("F:/" + name);

            if (sFile.exists()) {
                sFile.delete();
            }
            try {
                sFile.createNewFile();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            XesXmlSerializer xstream = new XesXmlSerializer();
            OutputStream oStream = new BufferedOutputStream(
                    new FileOutputStream(sFile));
            xstream.serialize(writeLog, oStream);

            XESBranch++;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * write log to xes file
     */
    private void writeToXES(XLog writeLog) {
        // wirteLog is empty
        if (writeLog.size() == 0) {
            System.out.print("\nwriteLog.size() == 0");
            return;
        }
        // get the size of events in writeLog
        System.out.print("\nwrite to XES");
        PropertiesReaderServices x1 = PropertiesReaderServicesImpl.instance();
        try {
            String name = resultFilePath + "_" + XESBranch + ".xes";

            File sFile = new File(x1.getProperties("XES_WRITE_PATH") + name);


            if (sFile.exists()) {
                sFile.delete();
            }
            try {
                sFile.createNewFile();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            XesXmlSerializer xstream = new XesXmlSerializer();
            OutputStream oStream = new BufferedOutputStream(
                    new FileOutputStream(sFile));
            xstream.serialize(writeLog, oStream);
            oStream.close();

            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(sFile);
            XMLOutputter outputter = new XMLOutputter();
            String xesString = outputter.outputString(doc);

            XESHelper xesh = new XESHelper();
            Date currentTime = new Date();

//             try {
//            String xesString = URLEncoder.encode(xesStringTemp, "UTF-8");
//             }catch(Exception e){
//                 PanGuConstants.MAX_EVENT_NUM= PanGuConstants.MAX_EVENT_NUM-1000;
//                 
//             }

            //   String  xesString=URLEncoder.encode(xesStringTemp, "UTF-8");

            DbXES dbxes = new DbXES(Integer.toString(XESBranch), resultFilePath, xesString, currentTime.toString(), classify);
            xesh.saveXES(dbxes);

            XESBranch++;
            try {
                //  sFile.delete();//dm
            } catch (Exception e) {
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        // display the timer
//        System.out.print("\ntime1_3_ReadFile:"
//                + Timer.formatDuration(time1_3_ReadFile));
//        System.out.print("\ntime4_WriteXES:"
//                + Timer.formatDuration(time4_WriteXES));
//        System.out.print("\ntime_setLogBuffer:"
//                + Timer.formatDuration(time_setLogBuffer));
//        System.out.print("\ntime_WriteToEvent:"
//                + Timer.formatDuration(time_WriteToEvent));
//        System.out.print("\ntime_WriteEventToLog:"
//                + Timer.formatDuration(time_WriteEventToLog));
//        System.out.print("\ntime_splitLog:"
//                + Timer.formatDuration(time_splitLog));
//        System.out.print("\ntotalTime:"
//                + Timer.formatDuration(getTimeTotal()));

    }

    public LogBuffer getTestLogBuffer() {
        return testLogBuffer;
    }

    public void setTestLogBuffer(LogBuffer logBuffer) {
        this.testLogBuffer = logBuffer;
    }

    public XLog getLog() {
        return log;
    }

    public void setLog(XLog log) {
        this.log = log;
    }

    private int getLogSize(XLog logL) {
        int events = 0;
        XLogInfo info = null;
        info = XLogInfoFactory.createLogInfo(logL);
        events += info.getNumberOfEvents();
        return events;
    }

    /**
     * @return the totalEvent
     */
    public int getTotalEvent() {
        return totalEvent;
    }

    /**
     * @param totalEvent the totalEvent to set
     */
    public void setTotalEvent(int totalEvent) {
        this.totalEvent = totalEvent;
    }

    /**
     * @return the caseBranchMap
     */
    public Hashtable<String, Integer> getCaseBranchMap() {
        return caseBranchMap;
    }

    /**
     * @param caseBranchMap the caseBranchMap to set
     */
    public void setCaseBranchMap(Hashtable<String, Integer> caseBranchMap) {
        this.caseBranchMap = caseBranchMap;
    }

    /**
     * @return the timeTotal
     */
    public long getTimeTotal() {
        return timeTotal;
    }

    /**
     * @param timeTotal the timeTotal to set
     */
    public void setTimeTotal(long timeTotal) {
        this.timeTotal = timeTotal;
    }
}
